import { List } from 'list-model.js';

var list = new List();

// 使用function初始化array，相比var initSubMenuDisplay = [] 既避免的引用复制的，同时方式更灵活，将来可以是多种方式实现，个数也不定的
function initSubMenuDisplay() {
  return ['hidden', 'hidden', 'hidden'];
}

//定义初始化数据，用于运行时保存
var initSubMenuHighLight = [
  ['', '', '', '', ''],
  ['', ''],
  ['', '', '']
];
var touchDot = 0;//触摸时的原点
var time = 0;//  时间记录，用于滑动时且时间小于1s则执行左右滑动
var interval = "";// 记录/清理 时间记录
var tmpFlag = true;// 判断左右华东超出菜单最大值时不再执行滑动事件


Page({
  data: {
    subMenuDisplay: initSubMenuDisplay(),
    subMenuHighLight: initSubMenuHighLight,
    goods: [],
    allList: '',
    requestList: '',
    page: 8,
    currentTab: 0
  },
  onLoad: function (options) {
    var categoryId = options.categoryId;
    this._loadData(categoryId);
  },
  _loadData: function (categoryId,callback) {
    var that = this;
    //获得热卖推荐信息
    this.getClassiData(categoryId,this.data.page);
  },
  getClassiData: function (categoryId,page) {
    var that = this;
    list.getClassiData(categoryId,page, (data) => {
      that.setData({
        goods: data['data'],
        allList: data[' allList'],
        requestList: data['requestList']
      });
    });
  },
  showDetail: function (e) {
    var goodsId = e.currentTarget.dataset.index;
    wx.navigateTo({
      url: "../../goods/detail/detail?objectId=" + goodsId
    });
  },
  onReachBottom: function () {
    if (this.data.allList != this.data.requestList) {
      this.getClassiData($,this.data.page + 1);
      wx.showToast({
        title: '加载中',
        icon: 'loading'
      })
    } else {
      //没有更多了
    }
  },
  onPullDownRefresh: function () {
    this.getClassiData(this.data.page);
  },
});